<?php 

namespace App\Exceptions;

use Exception;
use JsonSerializable;

class BaseException extends Exception implements JsonSerializable
{

    protected $defaultConfig = '';

    public function __construct($exceptionConfig, $message = null)
    {
        $exception = config($this->defaultConfig.$exceptionConfig);
        $message = is_null($message)? $exception['message'] : $message;

        parent::__construct($message, $exception['errCode']);
    }

    public function jsonSerialize()
    {
        return [
            'status' => [
                'errCode' => $this->getCode(),
                'message' => $this->getMessage()
            ],
        ];
    }
}